home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asmexam.arc / ASCBIN1.ASM < prev    next >
Assembly Source File  |  1984-07-05  |  2KB  |  86 lines

  1. page   55,80
  2. title  test program
  3.  
  4. cseg   segment
  5.        assume  cs:cseg,ds:cseg
  6. decnum: db '123','zzzz' ; z's are for extra locations
  7.        org 100h
  8.  
  9. main:
  10.        lea si,decnum
  11.        jmp  decbin
  12. back:  int 20h
  13.  
  14. decbin:
  15.        xor     cx,cx
  16.        xor     dx,dx
  17.        mov     bx,-1
  18.        mov     al,[si]
  19.        cmp     al,'+'
  20.        jne     decbin1
  21.        inc     si
  22.        jmp     decbin2
  23.  
  24. decbin1:
  25.        cmp     al,'-'
  26.        jne     decbin2
  27.        xor     bh,bh
  28.        inc     si
  29.  
  30. decbin2:
  31.        lodsb
  32.        or      al,al
  33.        jz      decbin8
  34.        cmp     al,'.'
  35.        jz      decbin4
  36.        cmp     al,'9'
  37.        ja      decbin7
  38.        cmp     al,'0'
  39.        jb      decbin7
  40.        or      bl,bl
  41.        js      decbin3
  42.        inc     bl
  43.  
  44. decbin3:
  45.        push    ax
  46.        mov     di,cx
  47.        mov     ax,dx
  48.        shl     cx,1
  49.        rcl     dx,1
  50.        shl     cx,1
  51.        rcl     dx,1
  52.        add     cx,di
  53.        adc     dx,ax
  54.        shl     cx,1
  55.        rcl     dx,1
  56.        pop     ax
  57.        and     ax,0fh
  58.        add     cx,ax
  59.        adc     dx,0
  60.        jmp     decbin2
  61.  
  62. decbin4:
  63.        or      bl,bl
  64.        jns     decbin7
  65.        xor     bl,bl
  66.        jmp     decbin2
  67.  
  68. decbin7:
  69.        stc
  70.        jmp back
  71.  
  72. decbin8:
  73.        or      bh,bh
  74.        jnz     decbin9
  75.        not     cx
  76.        not     dx
  77.        add     cx,1
  78.        adc     dx,0
  79.  
  80. decbin9:
  81.        clc
  82.        jmp back
  83. cseg  ends
  84.       end main
  85.  
  86.